package com.lipiao.traveltreasure.service.impl.travelTreasure;

import com.lipiao.traveltreasure.bean.travelTreasureBean.BaseUserBean;
import com.lipiao.traveltreasure.dao.traveltreasure.SellerMapper;
import com.lipiao.traveltreasure.service.travelTreasure.AllUserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * 所有用户 通用接口实现类
 * {1,2,3};//  平台管理员 1，商家 2，用户 3
 */
@Service
@Transactional
public class AllUserServiceImpl implements AllUserService {


    //注入Mapper接口对象
    @Resource
    SellerMapper sellerMapper;
    private static String strUserId = "-1";//登录 or 注册

    /**
     * 1.登录实现方法
     *
     * @param username 用户名
     * @param password 密码
     * @param userKind 使用者通过userKind区分 平台管理员，商家，用户
     * @return 返回用户ID  例如店铺(商家)返回 店铺id以便之后使用id查询对应店铺的活动等内容
     */
    @Override
    public String login(String username, String password, int userKind) {
        strUserId = "-1";//重置
        switch (userKind) {
            case 1:
                strUserId = "1";
                break;
            case 2://店铺(商家)
                strUserId = sellerMapper.login(username, password);
                break;
            case 3:
                strUserId = "3";
                break;
        }
        return strUserId;
    }

    /**
     * 2.注册实现方法
     *
     * @param username 用户名
     * @param password 密码
     * @param userKind 用户类型
     */
    @Override
    public void register(String username, String password, int userKind, String userId) {
        switch (userKind) {
            case 1:
                strUserId = "1";
                break;
            case 2://店铺(商家)
                sellerMapper.register(username, password, userId);
                break;
            case 3:
                strUserId = "3";
                break;
        }
        strUserId = "-1";//重置
    }

    @Override
    public void changePassword(String username, String password, String newPassword, int userKind) {
        switch (userKind) {
            case 1:
                strUserId = "1";
                break;
            case 2://店铺(商家)
                sellerMapper.changePassword(username, password, newPassword);
                break;
            case 3:
                strUserId = "3";
                break;
        }
    }

    @Override
    public void uploadPic(long userId, MultipartFile photo) {

    }

    @Override
    public void updateUserInformation() {
        //sellerMapper.updateUserInformation(SellerBean );
    }

    @Override
    public void loginOut() {

    }

    /**
     * 7.通过userId查找 返回对应的用户数据基类BaseUserBean
     *
     * @param userNumber 账号
     * @return 用户数据基类BaseUserBean
     */
    @Override
    public BaseUserBean findById(String userNumber) {
        return sellerMapper.findById(userNumber);
    }
}
